/**   
* @Title: Button.java
* @Package cn.edu.sjtu.se.dslab.component.design
* @Description: TODO(用一句话描述该文件做什么)
* @author longshaohang
* @date 2013-9-22 下午4:14:35
* @version V1.0
*/ 
package cn.edu.sjtu.se.dslab.component.design;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import cn.edu.sjtu.se.dslab.project.DisplayZone;
import cn.edu.sjtu.se.dslab.project.Project;


/** 
 * @ClassName: Button
 * @Description: Define the Button for the devices
 * @author longshaohang
 * @date 2013-9-22 下午4:14:35
 * 
 */
@Entity
@Table(name = "button")
public class Button implements Serializable,Comparable, Cloneable{
	private static final long serialVersionUID = -746755003308354771L;
	
	private long id;
	private String name;
	private String code;
	
	private Project project;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	
	@Column(nullable = false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(nullable = false)
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	
	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "project_id", nullable = false)
	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}
	@Override
	public int compareTo(Object o) {
		if(Button.class.isInstance(o)){
			Button b=(Button)o;
			return this.getCode().compareTo(b.getCode());
		}
		return 0;
	}
	
	
	@Override
	public Object clone() {
		Button button = null;
		try{
			button = (Button)super.clone();
			button.setId(0);
			button.setProject(null);
		}catch(CloneNotSupportedException ex){
			ex.printStackTrace();
		}
		return button;
	}
	
	
}
